package com.punai.customer.controller;

import cn.hutool.core.util.StrUtil;
import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.common.exception.ServiceException;
import com.punai.common.utils.StringUtils;
import com.punai.customer.domain.CusGxLinkGkCategories;
import com.punai.customer.domain.contants.CusConstants;
import com.punai.customer.domain.vo.CusLinkGkVo;
import com.punai.customer.service.ICusGxLinkGkCategoriesService;
import com.punai.customer.service.ICusLinkGxfeeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标准费用项下材料类别关联归口Controller
 * 
 * @author zhx
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/cus/cusGxLinkGkCategories")
public class CusGxLinkGkCategoriesController extends BaseController
{
    @Autowired
    private ICusGxLinkGkCategoriesService cusGxLinkGkCategoriesService;
    @Autowired
    private ICusLinkGxfeeCategoryService cusLinkGxfeeCategoryService;

    /**
     * 查询标准费用项下材料类别关联归口列表
     */
    @PreAuthorize("@ss.hasPermi('cus:cusGxLinkGkCategories:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusGxLinkGkCategories cusGxLinkGkCategories)
    {
        startPage();
        List<CusGxLinkGkCategories> list = cusGxLinkGkCategoriesService.selectCusGxLinkGkCategoriesList(cusGxLinkGkCategories);
        return getDataTable(list);
    }

    /**
     * 获取标准费用项下材料类别关联归口详细信息
     */
    @PreAuthorize("@ss.hasPermi('cus:cusGxLinkGkCategories:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cusGxLinkGkCategoriesService.selectCusGxLinkGkCategoriesById(id));
    }

    /**
     * 修改标准费用项下材料类别关联归口
     */
//    @PreAuthorize("@ss.hasPermi('cus:cusGxLinkGkCategories:edit')")
    @Log(title = CusConstants.GX_NAME + "-材料类别关联归口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusLinkGkVo cusLinkGkVo)
    {
        if(StringUtils.isEmpty(cusLinkGkVo.getSpecId())){
            return AjaxResult.error("专业获取失败");
        }
        if (!StrUtil.containsAny(cusLinkGkVo.getFeatureState(),"1","0")) {
            throw new ServiceException("特征描述状态参数错误!");
        }
        if (StringUtils.isNotEmpty(cusLinkGkVo.getUseRange()) && !StrUtil.containsAny(cusLinkGkVo.getUseRange(),CusConstants.USE_RANGE_FEE,CusConstants.USE_RANGE_FBGC,CusConstants.USE_RANGE_ZY)) {
            throw new ServiceException("应用范围值错误!");
        }
        return toAjax(cusGxLinkGkCategoriesService.updateCusGxLinkGkCategories(getCompanyId(),cusLinkGkVo));
    }

	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return AjaxResult.error("删除功能废弃");
//        return toAjax(cusGxLinkGkCategoriesService.deleteCusGxLinkGkCategoriesById(id,getCompanyId()));
    }

    @GetMapping(value = "/getGkByCategoryId/{categoryId}/{gkType}")
    public AjaxResult getGkByCategoryId(@PathVariable("categoryId") String categoryId,@PathVariable("gkType") String gkType)
    {
        return AjaxResult.success(cusGxLinkGkCategoriesService.getGkByCategoryId(categoryId,gkType,getCompanyId()));
    }

    @GetMapping("/getChildrenCategories/{gxLinkGkFeatureId}")
    public TableDataInfo getChildrenCategories(@PathVariable("gxLinkGkFeatureId") String gxLinkGkFeatureId)
    {
        return getDataTable(cusGxLinkGkCategoriesService.getChildrenCategories(gxLinkGkFeatureId,getCompanyId()));
    }

    @GetMapping("/getTwoChildrenCategories/{gxId}")
    public TableDataInfo getTwoChildrenCategories(@PathVariable("gxId") String gxId)
    {
        return getDataTable(cusLinkGxfeeCategoryService.getTwoChildrenCategories(gxId));
    }

    @GetMapping("/getHistoryCategories/{specId}/{gkType}")
    public TableDataInfo getHistoryCategories(@PathVariable("specId") String specId,@PathVariable("gkType") String gkType)
    {
        startPage();
        return getDataTable(cusGxLinkGkCategoriesService.getHistoryCategories(specId,gkType));
    }
}
